<?php

use yii\helpers\Html;
use yii\widgets\LinkPager;
use yii\grid\GridView;
use yii\bootstrap\Modal;
use app\common\Functions;
/**
 * @var yii\web\View $this
 * @var amnah\yii2\user\Module $module
 * @var array $actions
 */
global $regionTypes2;
global $prodAttrCodes;
$regionTypes2 = $regionTypes;
$module = $this->context->module;


$prodAttrCodes=[];



// 增加展示的字段
$columns = [];
$i = 0;


$columns[$i]['attribute'] = 'id';
$columns[$i]['options'] = ['style'=>'width:30px'];

//    $i++;
//    //订单类型
//    $columns[$i]['label'] = '订单类型';
//    $columns[$i]['attribute'] = 'order_type_id';
//    $columns[$i]['options'] = ['style'=>'width:90px'];
//    $columns[$i]['filter'] = Html::activeTextInput($searchModel, 'orderTypeName', ['class'=>'form-control']);
//    $columns[$i]['value']   = function($model)
//    {
//
//        return $model->orderTypes->type_name;
//
//    };


//    $i++;
//    //订单类型
//    $columns[$i]['label'] = '性质';
//    $columns[$i]['attribute'] = 'nature';
//    $columns[$i]['options'] = ['style'=>'width:60px'];
//    $columns[$i]['value']   = function($model) use($domains)
//    {
//        $natureName = $domains['order']['nature'][$model->nature]; $model->nature;
//        if ($natureName)
//        {
//            return $natureName;
//        }
//        return  ' ';
//    };




$i++;
//订单类型
$columns[$i]['label'] = '特性';
$columns[$i]['attribute'] = 'attr_spec_id';
$columns[$i]['options'] = ['style'=>'width:60px'];

$columns[$i]['value']   = function($model) use($attrSpecsDownList)
{

    if ( $model->custom_type!=1)
    {
        return $attrSpecsDownList[$model->attr_spec_id];

    }
    return '非特性';

};

$i++;
//订单类型
$columns[$i]['label'] = '关联名';
$columns[$i]['attribute'] = 'attr_field_name';
$columns[$i]['options'] = ['style'=>'width:60px'];




$i++;
//订单类型
$columns[$i]['label'] = '尺寸(px)';
$columns[$i]['attribute'] = 'attr_spec_width';
$columns[$i]['options'] = ['style'=>'width:60px'];

$i++;
//订单类型
$customTypes = ['1'=>'固定字段','0'=>'可选字段'];
$columns[$i]['label'] = '类型';
$columns[$i]['attribute'] = 'custom_type';
$columns[$i]['options'] = ['style'=>'width:60px'];
$columns[$i]['value']   = function($model) use($customTypes)
{

    return $customTypes[$model->custom_type];

};

$i++;
//订单类型
$columns[$i]['label'] = '别名';
$columns[$i]['attribute'] = 'show_name';
$columns[$i]['options'] = ['style'=>'width:60px'];

$i++;
//订单类型
$columns[$i]['label'] = '是否显示';
$columns[$i]['attribute'] = 'hide_flag';
$columns[$i]['options'] = ['style'=>'width:80px'];

$i++;
//订单类型
$columns[$i]['label'] = '排序';
$columns[$i]['attribute'] = 'sort';
$columns[$i]['options'] = ['style'=>'width:60px'];






        $i++;
        //操作选项
        // $columns[$i]['class']   = 'app\common\grid\ActionColumn';
        $columns[$i]['options'] = ['style'=>'width:80px'];

        $columns[$i]['content']   = function($model) use ($now_url)
        {

            $hideFlagText =  ($model->hide_flag==1) ? "隐藏" : '显示';
            $btns = [];

            $btnBegin = Html::a( '上移', ['up', 'id'=>$model->id, 'last_url'=> $now_url ], ['class' => "btn btn-xs btn-warning",'label'=>'上移', 'title' => '上移']);
            $btns[]   = Html::a( '上移', ['up', 'id'=>$model->id, 'last_url'=> $now_url ], [ 'label'=>'上移', 'title' => '上移']);
            $btns[]   = Html::a( '下移', ['down', 'id'=>$model->id, 'last_url'=> $now_url ], [ 'label'=>'下移', 'title' => '下移']);
            $btns[]   = Html::a( '置顶', ['top', 'id'=>$model->id , 'last_url'=> $now_url], [ 'label'=>'置顶', 'title' => '置顶']);
            $btns[]   = Html::a( '置底', ['bottom', 'id'=>$model->id, 'last_url'=> $now_url ], [ 'label'=>'置底', 'title' => '置底']);
            $btns[]   = Html::a( '修改内容', ['update', 'id'=>$model->id, 'last_url'=> $now_url ], [ 'label'=>'修改内容', 'title' => '修改内容']);
            $btns[]   = Html::a( '删除', ['delete', 'id'=>$model->id , 'last_url'=> $now_url], [ 'label'=>'删除', 'title' => '删除']);

            $btns[]   = Html::a( $hideFlagText, ['hide', 'id'=>$model->id , 'last_url'=> $now_url], [ 'label'=>$hideFlagText, 'title' => $hideFlagText]);



            return Functions::getActionDropdownContext($btnBegin, $btns);

        };





//        $columns[$i]['buttons'] =  [
//            'view' => function ($url, $model, $key) use ($prodSpecName) {
//                return Html::a(Html::tag('span', '查看', ['class' => "glyphicon fa fa-eye"]), ['view', 'id'=>$model->id,   'attr_type_spec_id'=> $model->object_type_id,    'prod_spec_name' => $prodSpecName], ['class' => "btn btn-xs btn-success",'label'=>'查看子产品', 'title' => '查看子产品']);
//            },
//
//            'update' => function ($url, $model, $key) use ($prodSpecName) {
//                return Html::a(Html::tag('span', '编辑', ['class' => "glyphicon fa fa-edit"]), [ ], ['class' => "btn btn-xs btn-success",'label'=>'查看子产品', 'title' => '查看子产品']);
//            },
//
//            'delete' => function ($url, $model, $key)  {
//                return Html::a(Html::tag('span', '删除', ['class' => "glyphicon fa fa-trash"]), ['delete', 'id'=>$model->id,   'attr_type_spec_id'=> $model->object_type_id ], ['class' => "btn btn-xs btn-danger",'label'=>'删除产品', 'title' => '删除子产品']);
//            },
//
//            'create' => function ($url, $model, $key)  {
//                return Html::a(Html::tag('span', '抢', ['class' => "glyphicon fa fa-flash"]), ['grab', 'id'=>$model->id ], ['class' => "btn btn-xs btn-info",'label'=>'抢单', 'title' => '抢单']);
//            },
//
//
//
//        ];

//}


?>

<?php
//'layout' => "{items}{summary}{pager}",
echo GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'layout' => "{items}{summary}{pager}",
    'options'=>['id'=>'grid', 'class'=>'col-sm-12'],
    'tableOptions'=>[ 'class'=>'table table-bordered table-striped dataTable'],
    'columns' => $columns,
    /*  'components' => ['formatter' => ['datetimeFormat' => 'yyyy-MM-dd HH:mm:',]]*/

]);


$js = <<<JS
jQuery('.activity-black-list-link').on('click',function() {
    $('.document-black-list-form').remove();
    $.get(
        '/prod/order/blacklist',
        {
            order_id: $(this).data('order-id')
        },
        function (data) {
            $('.modal-dialog').html(data);
            $('#black-list-modal').modal();
        }
    );
});
JS;
$this->registerJs($js);



// Pjax::end();
Modal::begin([
    'id' => 'black-list-modal',
    'class' => 'modal modal-primary',
    'header' => '<h4 class="modal-title">创建</h4>',
    'footer' => '<a href="#" class="btn btn-primary" data-dismiss="modal">Close</a>',
]);
Modal::end();


?>



